package com.grt192.benchtest.controller;

import com.grt192.benchtest.mechanism.BenchKicker;
import com.grt192.core.EventController;
import com.grt192.event.SensorChangeListener;
import com.grt192.event.SensorEvent;
import com.grt192.event.component.ButtonListener;
import com.grt192.event.component.SwitchListener;
import com.grt192.mechanism.GRTDriverStation;
import com.grt192.sensor.GRTJoystick;
import com.grt192.sensor.GRTSwitch;

/**
 *
 * @author anand
 */
public class BenchKickerController extends EventController implements ButtonListener, SensorChangeListener {

    private BenchKicker kicker;
    private GRTDriverStation ds;

    public BenchKickerController(BenchKicker k, GRTDriverStation ds) {
        this.ds = ds;
        ((GRTJoystick) ds.getSensor("leftJoystick")).addButtonListener(this);
        kicker = k;
        ((GRTSwitch) k.getSensor("switch")).addSensorChangeListener(this);
    }

    public void buttonUp(SensorEvent e, String key) {
        if (key.equals("Button1") || key.equals("Button2")) {
            kicker.stop();
        }
    }

    public void buttonDown(SensorEvent e, String key) {
        if (key.equals("Button1")) {
            kicker.spinForward();
        } else if (key.equals("Button2")) {
            kicker.spinReverse();
        }
    }

    public void sensorStateChanged(SensorEvent e, String key) {
        System.out.println("K SWITCH");
    }
}
